const myclass = require('../models/class')

/**
 * 
 * 测试用添加班级
 * 
 */
var cteateClass = async (ctx,next)=>{
    var className = ctx.request.body.className;
    var teacher = ctx.request.body.teacher;
    var classNum = ctx.request.body.classNum;
    var account1 = ctx.request.body.account1;
    var name1 = ctx.request.body.name1;
    var submit1 = new Array()
    var account2 = ctx.request.body.account2;
    var name2 = ctx.request.body.name2;
    var submit2 = new Array()
    // var student = {student1:[account1,name1,submit1],student2:[account2,name2,submit2]}
    var student = [{account:account1,name:name1,submit:submit1},{account:account2,name:name2,submit:submit2}]

    var classEntity = new myclass({
        className:className,
        teacher:teacher,
        classNum:classNum,
        student:student
    })
    classEntity.save(function(err,doc){
        if(err){
            console.log(err);
        }else{
            console.log(doc);
        }
    })
    return ctx.response.body = {stauts:'success',msg:'成功',classEntity};
}

/**
 * 
 * 获取班级数据
 * 
 * 
 */
var getclass = async (ctx,next)=>{
    try{
        let target_class = await myclass.findOne({className:ctx.request.body.className})
        return ctx.response.body = {stauts:'success',msg:'成功',target_class};
    }catch(err){
        console.log(err)
    }
    
}
module.exports = {
    'POST /class/cteateClass': cteateClass,
    'POST /class/getclass': getclass,
}